/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chat;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;

/**
 *
 * @author spider391Tang
 */
 //This listens for and reports caret movements.
    public class MouseTraceLabel extends JLabel
            implements MouseListener,MouseMotionListener{

        private String name = "";

        /**
         * Get the value of name
         *
         * @return the value of name
         */
        public String getName() {
            return name;
        }

        /**
         * Set the value of name
         *
         * @param name new value of name
         */
        public void setName(String name) {
            this.name = name;
        }

        public MouseTraceLabel(String label) {
            super(label);
        }

         public MouseTraceLabel() {
            super("");
        }



        /* Empty method definitions. */
        public void mousePressed(MouseEvent e) {
            //displaySelectionInfo(e.getX(),e.getY());
        }

        public void mouseReleased(MouseEvent e) {
        }

        public void mouseEntered(MouseEvent e) {
            //displaySelectionInfo(e.getX(),e.getY());
        }

        public void mouseExited(MouseEvent e) {
        }

        public void mouseClicked(MouseEvent e) {
           //Event handler implementation goes here...

            displaySelectionInfo(e.getX(),e.getY());

        }
        //This method can be invoked from any thread.  It
        //invokes the setText and modelToView methods, which
        //must run on the event dispatch thread. We use
        //invokeLater to schedule the code for execution
        //on the event dispatch thread.
        protected void displaySelectionInfo(final int x,
                final int y) {
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                     setText("position: (" + x + "," + y + ")");
                }
            });
        }

    public void mouseDragged(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseMoved(MouseEvent e) {
        displaySelectionInfo(e.getX(),e.getY());
    }
    }
